<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
</head>

<body>
    <h2>注册</h2>
    <form id="registerForm">
        <label>用户名<input type="text" name="username" id="username"></label><br>
        <label>密码<input type="password" name="password" id="password"></label><br>
        <label>确认密码<input type="password" name="password2" id="password2"></label><br>
        <button type="submit">注册</button><br>
    </form>

    <script>
        document.getElementById('registerForm').addEventListener('submit', function (event) {
            event.preventDefault()
            const username = document.getElementById("username").value; 
            const password = document.getElementById("password").value; 
            const password2 = document.getElementById("password2").value; 
            if (password != password2) {
                alert("两次输入的密码不一致，请检查");
                return;
            } else {
                fetch('/register', {
                    method: 'POST',
                    body: new URLSearchParams({
                        username: username,
                        password: password,
                        password2: password2
                    })
                }).then(response => response.text())
                    .then(message => {
                        alert(message)
                    })
            }
        })
    </script>
</body>

</html>